package components.banners
{
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import components.clt_component;
	
	import flash.display.Loader;
	import flash.events.Event;
	import flash.net.URLRequest;

	public class clt_topBannersMM extends clt_component {
	    private const genders: Object = ['f', 'm'];
	    private const bscale: Number = 0.63;
	    private var banners: Array = [
	    	'http://start.fotostrana.ru/vkontakte/part_dating/fotostrana_partners_600x120.swf',
	    	'http://start.fotostrana.ru/vkontakte/part_dating/600x120_marks.swf',
	    	'http://start.fotostrana.ru/promo/fotostrana/600x120/600x120_meet.swf',
	    	'http://start.fotostrana.ru/promo/fotostrana/600x120/600x120_guess_1.swf'
/*	    	'http://start.fotostrana.ru/vkontakte/dating/600x120/600x120_master.swf',
	    	'http://start.fotostrana.ru/vkontakte/dating/600x120/600x120_gift.swf'*/
	    ]
	    
	    private var bannerTest: String = 'http://start.fotostrana.ru/promo/apps/dating/600x120.swf?link1=http://my.mail.ru/apps/613897?ref=inst552302034';
	    
/*	    private var banners: Array = [
	    	'http://start.fotostrana.ru/vkontakte/dating/600x120/600x120_dating1.swf',
	    	'http://start.fotostrana.ru/vkontakte/dating/600x120/600x120_dating2.swf',
	    	'http://start.fotostrana.ru/vkontakte/dating/600x120/600x120_dating3.swf'
	    ]*/
	    
//		public function pi_ad2(parent: uif_component, ref_id: String = '754339891', asMail: Boolean=true) {
		public function clt_topBannersMM(parent: uif_component, ref_id: String = '468282879', asMail: Boolean=true) {
			super(parent, 0, 0, 760, 76);
			var user: Object = (app as clt_clothingBase).user;
	        var params: String = "?ref_id=" + ref_id + "&first_name=" + (user.first_name?user.first_name:user.nick) + "&sex=" + (2 - user.sex).toString() + 
	        			"&gender=" + genders[user.sex] + "&bdate=" + user.birthday + "&photo_url=" + (user.pic_big?user.pic_big:user.pic) + (asMail?"&source=633":'');
	        var urls: Array = [];
	        if (Math.random() >= 0.5) {
	        	urls.push(popURL() + params);
	        	urls.push(bannerTest);
	        } else {
	        	urls.push(bannerTest);
	        	urls.push(popURL() + params);
	        }
	        
			loadBanner(0, urls[0]);
			loadBanner(380, urls[1]);
		}
		
		private function popURL(): String {
			var index: int = Math.floor(Math.random() * banners.length);
			var result: String = banners[index];
			banners.splice(index, 1);
			return result;
		}
		
		private function loadBanner(ax: int, bannerURL: String): void {
			var loader: Loader = new Loader();
			var _mask: uif_ecomponent = new uif_ecomponent(this, ax, 0, 380, 76, 'white');
			loader.load(new URLRequest(encodeURI(bannerURL)));
			loader.mask = _mask;
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e: Event): void {
				loader.scaleX	= bscale;
				loader.scaleY	= bscale;
				loader.x 		= ax;
				addChild(loader);
			});
		};
	}
}